import request from "@/utils/request";

// 观察发现 返回的无论是一级分类、二级分类、三级分类 里面都有id和name 如果是获取二级分类里面的对象多category1Id 如果是获取三级分类里面的对象多category2Id
// 内容都差不多 所以统一定义他们的类型

interface CategoryData {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}

export type CategoryListData = CategoryData[];

export default {
  // GET  /admin/product/getCategory1
  // getCategory1
  getCategory1() {
    return request.get<any, CategoryListData>(`/admin/product/getCategory1`);
  },

  // GET /admin/product/getCategory2/{category1Id}
  // getCategory2
  getCategory2(category1Id: number) {
    return request.get<any, CategoryListData>(
      `/admin/product/getCategory2/${category1Id}`
    );
  },

  // GET /admin/product/getCategory3/{category2Id}
  // getCategory3
  getCategory3(category2Id: number) {
    return request.get<any, CategoryListData>(
      `/admin/product/getCategory3/${category2Id}`
    );
  },
};
